package or;

import java.util.Arrays;
import java.util.Comparator;

public class T2580 {
    private static final long MOD = (long) 1e9 + 7;
    public int countWays(int[][] ranges) {
        Arrays.sort(ranges, Comparator.comparingInt(o -> o[0]));
        int sum=1;
        int max=ranges[0][1];
        for (int i = 1; i < ranges.length ; i++) {
            if(ranges[i][0]>max){
                sum++;
            }
            max=Math.max(max,ranges[i][1]);
        }
        return (int) qpow(2,sum);
    }
    private static long qpow(long a, long b) {
        long ans = 1;
        while (b > 0) {
            if ((b & 1) == 1) ans = ans * a % MOD;
            a = a * a % MOD;
            b >>= 1;
        }
        return ans % MOD;
    }
}
